﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SerializedData;

namespace KnowledgeBaseManager
{
    public partial class AddSensor : Form
    {
        private DataCollection mDataCollection = DataCollection.Instance; 
        private SSensor mSensor;
        public AddSensor(SSensor sensor)
        {
            InitializeComponent();
            mSensor = sensor;
            textBox1.Text = sensor.getName();
            textBox2.Text = sensor.getUdp();
            

            listViewO.Clear();
            listViewO.BeginUpdate();
            listViewO.Columns.Add("CID", 50);
            listViewO.Columns.Add("Name", 200);
            listViewO.Columns.Add("Description", 150);

            foreach (SState sState in mDataCollection.getStatePool())
            {
                ListViewItem oneRow = listViewO.Items.Add("" + sState.getId());
                oneRow.SubItems.Add(sState.getName());
                oneRow.SubItems.Add(sState.getDescription());
            }
            listViewO.EndUpdate();
            
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void AddSensor_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            mSensor.setName(textBox1.Text);
            mSensor.setUdp(textBox2.Text);
            foreach (ListViewItem item in listViewO.SelectedItems)
            {
                mSensor.setRefState(long.Parse(item.Text));
            }
            mDataCollection.modifyOrAddSensor(mSensor);
            ((MainWindow)this.Owner).refreshSensorList();
            this.Close();


        }
    }
}
